package com.pic.mgt.syushin.converter;

import java.io.IOException;

import com.pic.mgt.monitor.MessageUnitConverter;
import com.pic.mgt.monitor.WrongUnitFormatException;
import com.pic.mgt.monitor.parser.FormatParser;
import com.pic.mgt.syushin.unit.SyushinMessage;
import com.pic.mgt.unit.Unit;

public abstract class SyushinMessageUnitConverter extends MessageUnitConverter {
	// (送多方新增)
	private SyushinMessage syushinMessageUnit;
	
	// (送多方新增)
	private FormatParser syushinMessageApNameParser;
	
	@Override
	protected void parseIGXTypeContent(Unit unit) throws IOException, WrongUnitFormatException {
		// (送多方新增)
		this.syushinMessageUnit = (SyushinMessage)unit;
		
		// (送多方新增)
		doFill();
		
		parseBusinessTypeContent(unit);
	}
	
	/*
	 * 放入業務型態內容資訊:
	 * (1) Ap Name
	 */
	// (送多方新增)
	private void doFill() throws WrongUnitFormatException {
		// --------------------- (1) Ap Name ---------------------
		// throws WrongUnitFormatException
		fillApName();
	}
	
	// (送多方新增)
	private void fillApName() throws WrongUnitFormatException  {
		this.syushinMessageUnit.setApName((String)this.syushinMessageApNameParser.parse(this.syushinMessageUnit.getConfirmationFile()));
	}
	
	protected abstract void parseBusinessTypeContent(Unit unit)
								throws IOException, WrongUnitFormatException;
	
	// (送多方新增)
	public void setSyushinMessageApNameParser(
			FormatParser syushinMessageApNameParser) {
		this.syushinMessageApNameParser = syushinMessageApNameParser;
	}
}
